<!--
 * @Description: 浪潮综合信息统计管理
 * @Version: 2.0
 * @Autor: 许国辉
 * @Date: 2022-10-26 08:21:01
 * @LastEditors: 许国辉
 * @LastEditTime: 2025-02-19 16:15:33
-->
<template>
  <div>
    <Card :bordered="false" style="background-color: white; width: 98%; margin: 20px auto 0px">
      <PageWrapper>
        <Row>
          <Col span="24">
            <Row>
              <Col span="12"
                >查询日期：

                <a-range-picker
                  format="YYYY-MM-DD"
                  @change="onChange"
                  showToday
                  :default-value="[getCurrentDataL(), getCurrentDataR()]"
                  style="margin-right: 10px"
                />
                <a-button
                  type="primary"
                  :loading="
                    searchBits[0] &&
                    searchBits[1] &&
                    searchBits[2] &&
                    searchBits[3] &&
                    searchBits[4]
                  "
                  @click="searchData"
                >
                  <template #icon><SearchOutlined /></template>
                  数据查询
                </a-button>

                <a-button
                  type="primary"
                  style="margin-left: 10px"
                  @click="allExport"
                  :disabled="
                    searchBits[0] &&
                    searchBits[1] &&
                    searchBits[2] &&
                    searchBits[3] &&
                    searchBits[4]
                  "
                  :loading="
                    exportDataBit[0] &&
                    exportDataBit[1] &&
                    exportDataBit[2] &&
                    exportDataBit[3] &&
                    exportDataBit[4]
                  "
                >
                  导出表格
                </a-button>
              </Col>
            </Row>
          </Col>
        </Row>
      </PageWrapper>
    </Card>
    <Card :bordered="false" style="background-color: white; width: 98%; margin: 20px auto 0px">
      <a-tabs v-model:activeKey="tabActiveKey">
        <!-- <a-tabs v-model:activeKey="activeKey" @change="tabChange"></a-tabs> -->
        <a-tab-pane key="1" tab="机票订单" style="background-color: rgba(144, 147, 153, 0.3)">
          <BasicTable @register="registerTableAir" :searchInfo="searchInfo" />
        </a-tab-pane>
        <a-tab-pane key="2" tab="火车订单">
          <BasicTable @register="registerTableTrain" :searchInfo="searchInfo" />
        </a-tab-pane>
        <a-tab-pane key="3" tab="酒店订单">
          <BasicTable @register="registerTableHotel" :searchInfo="searchInfo" />
        </a-tab-pane>
        <a-tab-pane key="4" tab="用车订单">
          <BasicTable @register="registerTableCar" :searchInfo="searchInfo" />
        </a-tab-pane>
        <a-tab-pane key="5" tab="补助">
          <BasicTable @register="registerTableSubsidy" :searchInfo="searchInfo" />
        </a-tab-pane>
      </a-tabs>
      <!-- <BasicTable @register="registerTable" /> -->
      <!-- <BasicTable @register="registerTable" :searchInfo="searchInfo" /> -->
    </Card>
  </div>
</template>
<script lang="ts" setup>
  import { nextTick, onMounted, reactive, ref } from 'vue';
  import { Card, Row, Col } from 'ant-design-vue';
  // import type { DatePickerProps } from 'ant-design-vue';
  import { PageWrapper } from '/@/components/Page';
  import { BasicTable, useTable } from '/@/components/Table';
  import { comprehensiveAirColumns } from './comprehensiveAirData';
  import { comprehensiveCarColumns } from './comprehensiveCarData';
  import { comprehensiveHotelDataCoumns } from './comprehensiveHotelData';
  import { comprehensiveTrainColumns } from './comprehensiveTrainData';
  import { comprehensiveSubsidyColumns } from './comprehensiveSubsidyData';
  import { ComprehensiveAirModel } from '/@/api/model/comprehensive/ComprehensiveAirModel';
  import { ComprehensiveCarModel } from '../../../api/model/comprehensive/ComprehensiveCarModel';
  import { ComprehensiveHotelModel } from '../../../api/model/comprehensive/ComprehensiveHotelModel';
  import { ComprehensiveTrainModel } from '../../../api/model/comprehensive/ComprehensiveTrainModel';
  import { ComprehensiveSubsidyModel } from '../../../api/model/comprehensive/ComprehensiveSubsidyModel';
  import { reportsHeaderAir, airHeaderDisplay } from './reportExcel/excelAir';
  import { reportsHeaderCar, carHeaderDisplay } from './reportExcel/excelCar';
  import { reportsHeaderHotel, hotelHeaderDisplay } from './reportExcel/excelHotel';
  import { reportsHeaderTrain, trainHeaderDisplay } from './reportExcel/excelTrain';
  import { reportsHeaderSubsidy, subsidyHeaderDisplay } from './reportExcel/excelSubsidy';
  import dayjs from 'dayjs';
  import * as XLSX from 'xlsx'; //这是vue3导入XLSX的方法
  import FileSaver from 'file-saver';
  import XLSXStyle from 'xlsx-style-vite';
  import {
    getComprehensiveAir,
    getComprehensiveAll,
    getComprehensiveCar,
    getComprehensiveHotel,
    getComprehensiveTrain,
    getComprehensiveSubsidy,
  } from '/@/api/orderStaiistics/comprehensiveAPI';
  // 查询状态标志
  let searchBits = ref([false, false, false, false, false]);
  // 导出数据准备状态
  let exportDataBit = ref([false, false, false, false, false]);
  let rangeChooseDate = ref([getCurrentDataL(), getCurrentDataR()]);
  const searchInfo = reactive<Recordable>({});
  //获得当前年份4位年
  function getCurrentDataL() {
    return dayjs(dayjs().year().toString() + '-' + Number(dayjs().month()) + '-16');
  }
  function getCurrentDataR() {
    // return new Date().toLocaleDateString();
    return dayjs(dayjs().year().toString() + '-' + Number(dayjs().month() + 1) + '-15');
  }
  let tabActiveKey = ref('1');
  let tableAirData: ComprehensiveAirModel[];
  let tableHotelData: ComprehensiveHotelModel[];
  let tableTrainData: ComprehensiveTrainModel[];
  let tableCarData: ComprehensiveCarModel[];
  let tableSubsidyData: ComprehensiveSubsidyModel[];
  const [registerTableAir, { reload: reloadAir, setColumns: setColumnsAir }] = useTable({
    api: getComprehensiveAir,
    pagination: { pageSize: 10 },
    columns: comprehensiveAirColumns,
    showTableSetting: true,
    tableSetting: { fullScreen: true },
    striped: false,
    useSearchForm: false,
    bordered: true,
    showIndexColumn: true,
  });

  const [registerTableHotel, { reload: reloadHotel, setColumns: setColumnsHotel }] = useTable({
    api: getComprehensiveHotel,
    pagination: { pageSize: 10 },
    columns: comprehensiveHotelDataCoumns,
    showTableSetting: true,
    tableSetting: { fullScreen: true },
    striped: false,
    useSearchForm: false,
    bordered: true,
    showIndexColumn: true,
  });

  const [registerTableTrain, { reload: reloadTrain, setColumns: setColumnsTrain }] = useTable({
    api: getComprehensiveTrain,
    pagination: { pageSize: 10 },
    columns: comprehensiveTrainColumns,
    showTableSetting: true,
    tableSetting: { fullScreen: true },
    striped: false,
    useSearchForm: false,
    bordered: true,
    showIndexColumn: true,
  });

  const [registerTableCar, { reload: reloadCar, setColumns: setColumnsCar }] = useTable({
    api: getComprehensiveCar,
    pagination: { pageSize: 10 },
    columns: comprehensiveCarColumns,
    showTableSetting: true,
    tableSetting: { fullScreen: true },
    striped: false,
    useSearchForm: false,
    bordered: true,
    showIndexColumn: true,
  });
  const [registerTableSubsidy, { reload: reloadSubsidy, setColumns: setColumnsSubsidy }] = useTable(
    {
      api: getComprehensiveSubsidy,
      pagination: { pageSize: 10 },
      columns: comprehensiveSubsidyColumns,
      showTableSetting: true,
      tableSetting: { fullScreen: true },
      striped: false,
      useSearchForm: false,
      bordered: true,
      showIndexColumn: true,
    },
  );
  var excelname = '';
  const onChange = async (date, dateString) => {
    excelname = dateString;
    if (date != null) {
      rangeChooseDate.value = dateString;
      searchInfo.chooseDate = rangeChooseDate.value;
      searchBits.value[0] = false;
      searchBits.value[1] = false;
      searchBits.value[2] = false;
      searchBits.value[3] = false;
      searchBits.value[4] = false;
    }
  };

  // const tabChange = (activeKey: string) => {
  //   searchInfo.chooseDate = rangeChooseDate.value;
  //   nextTick(async () => {
  //     if (activeKey == '1') {
  //       setColumnsAir(comprehensiveAirColumns);
  //       setTimeout(() => {
  //         reloadAir();
  //       }, 800);
  //     } else if (activeKey == '2') {
  //       setColumnsTrain(comprehensiveTrainColumns);
  //       setTimeout(() => {
  //         reloadTrain();
  //       }, 800);
  //     } else if (activeKey == '3') {
  //       setColumnsHotel(comprehensiveHotelDataCoumns);
  //       setTimeout(() => {
  //         reloadHotel();
  //       }, 800);
  //     } else if (activeKey == '4') {
  //       setColumnsCar(comprehensiveCarColumns);
  //       setTimeout(() => {
  //         reloadCar();
  //       }, 800);
  //     } else if (activeKey == '5') {
  //       setColumnsSubsidy(comprehensiveSubsidyColumns);
  //       setTimeout(() => {
  //         reloadSubsidy();
  //       }, 800);
  //     }
  //   });
  // };
  function getDays(startDateString, endDateString) {
    const start = new Date(startDateString);
    const end = new Date(endDateString);
    const millisecondsPerDay = 1000 * 60 * 60 * 24;
    // 一天的毫秒数
    const millisecondsDiff = end.getTime() - start.getTime();
    // 获取毫秒差值
    const daysDiff = Math.ceil(millisecondsDiff / millisecondsPerDay);
    // 计算相差的天数
    return daysDiff;
  }
  // 全部導出
  const allExport = async () => {
    exportDataBit.value[0] = true;
    exportDataBit.value[1] = true;
    exportDataBit.value[2] = true;
    exportDataBit.value[3] = true;
    exportDataBit.value[4] = true;
    await getComprehensiveSubsidy({ chooseDate: rangeChooseDate.value }).then((data) => {
      tableSubsidyData = data.items;
    });

    await getComprehensiveAll({ chooseDate: rangeChooseDate.value }).then((data) => {
      tableAirData = data.airRecordList;
      tableTrainData = data.trainRecordList;

      tableHotelData = data.hotelRecordList;
      tableCarData = data.carRecordList;
    });
    var airRecord: object[] = [];
    var hotelRecord: object[] = [];
    var trainRecord: object[] = [];
    var carRecord: object[] = [];
    var subsidyRecord: object[] = [];
    //飞机
    for (let i = 0; i < tableAirData.length; i++) {
      let airModel = {
        id: 1,
        zdlx: '终端类型',
        outTicketDate: '出票日期',
        bookerName: '预定人姓名',
        bookerTel: '预定人手机',
        exNum: '审批单号',
        a1: '审批出发日期',
        a2: '审批返回日期',
        empNo: '员工编号',
        pnr: 'PNR',
        cabinAllPrice: 0,
        tickerNo: '票号',
        empName: '员工姓名',
        empTel: '员工电话',
        voyage: '行程',
        flightNum: '航班号',
        carrierName: '航空公司',
        deptDate: '出发日期',
        deptTime: '出发时间',
        arriveDate: '抵达日期',
        arriveTime: '抵达时间',
        cabinCode: '舱位',
        salePrice: 0,
        taxSum: 0,
        planePriceSum: 0,
        changeFreeSum: 0,
        refundBeAmount: 0,
        insurance: 0,
        a3: 0,
        a4: 0,
        agio: 0,
        ticketServicePrice: 0,
        priceBy: 0,
        refundPrice: 0,
        ticketPrice: 0,
        ticketPriceSum: 0,
        a5: '订票方式',
        a6: '结算',
        a7: '白云对帐',
        a8: '支付时间',
        bookingType: '订票类型',
        a10: '机票类型',
        remark: '备注',
        empIdNum: '身份证号',
        a12: '消费记录id',
        // a13: '订单号',
        a14: '乘机人卡号',
        a15: '出发城市',
        a16: '到达地',
        a69: '员工部门',
        a70: '订单号',
      };
      let record = tableAirData[i];
      airModel.id = i + 1;
      airModel.zdlx = record.cid === '70001' ? 'PC' : 'app';
      airModel.outTicketDate = dayjs(record.outTicketDate).format('YYYY/MM/DD HH:mm:ss');
      airModel.bookerName = record.bookerName;
      airModel.bookerTel = record.bookerTel;
      airModel.exNum = record.exNum;
      airModel.a1 = record.dateOfDeparture
        ? dayjs(record.dateOfDeparture).format('YYYY/MM/DD')
        : '';
      airModel.a2 = record.dateOfReturn ? dayjs(record.dateOfReturn).format('YYYY/MM/DD') : '';
      airModel.empNo = record.empNo;
      airModel.pnr = record.pnr;
      airModel.cabinAllPrice = record.cabinAllPrice;
      airModel.tickerNo = record.tickerNo;
      airModel.empName = record.empName;
      airModel.empTel = record.empTel;
      airModel.voyage = record.voyage;
      airModel.flightNum = record.flightNum;
      airModel.carrierName = record.carrierName + '(' + record.carrierCode + ')';
      airModel.deptDate = airModel.deptDate ? dayjs(record.deptDate).format('YYYY/MM/DD') : '-';
      airModel.deptTime = record.deptTime + ':00';
      airModel.arriveDate = airModel.arriveDate
        ? dayjs(record.arriveDate).format('YYYY/MM/DD')
        : '-';
      airModel.arriveTime = record.arriveTime + ':00';
      airModel.cabinCode = record.cabinCode;
      airModel.salePrice = record.salePrice;
      airModel.taxSum = record.taxSum;
      airModel.planePriceSum = record.planePriceSum;
      airModel.changeFreeSum = record.changeFee + record.changeUpFee;
      airModel.refundBeAmount = record.refundBeAmount;
      airModel.insurance = record.insurance;
      airModel.a3 = 0;
      airModel.a4 = 0;
      airModel.agio = record.agio;
      airModel.ticketServicePrice = record.ticketServicePrice;

      // 深白云扣款 应收 总金额包含服务费
      if (record.bookingType === '改期单') {
        airModel.priceBy = record.changeUpFee + record.changeFee;
        airModel.ticketPrice = record.changeFee + record.changeUpFee;
        airModel.ticketPriceSum = record.changeFee + record.changeUpFee + record.ticketServicePrice;
      } else if (record.bookingType === '退票单') {
        airModel.priceBy =
          record.refundPrice +
          record.ticketPrice -
          record.insurance +
          record.changeUpFee +
          record.changeFee;
        airModel.ticketPrice =
          record.refundPrice +
          record.ticketPrice -
          record.insurance +
          record.changeUpFee +
          record.changeFee;
        airModel.ticketPriceSum =
          record.refundPrice +
          record.ticketPriceSum +
          record.changeUpFee +
          record.changeFee +
          record.insurance;
      } else {
        airModel.priceBy = record.ticketPrice + record.insurance;
        airModel.ticketPrice = record.ticketPrice + record.insurance;
        airModel.ticketPriceSum = record.ticketPriceSum + record.insurance;
      }

      // airModel.priceBy = record.priceBy;
      airModel.refundPrice = record.refundPrice;
      // airModel.ticketPrice = record.ticketPrice;
      // airModel.ticketPriceSum = record.ticketPriceSum;
      airModel.a5 = '有审批单';
      airModel.a6 = '-';
      airModel.a7 = '-';
      airModel.a8 = record.payDate ? dayjs(record.payDate).format('YYYY/MM/DD') : '-';
      airModel.bookingType = record.bookingType;
      airModel.a10 = record.belongType;
      airModel.remark = record.remark ? record.remark : '-';
      airModel.empIdNum = 'ID:' + record.empIdNum;
      airModel.a12 = 'flight' + record.id;
      // airModel.a13 = record.orderNum;
      airModel.a14 = record.empIdNum;
      airModel.a15 = record.orgName;
      airModel.a16 = record.dstName;
      airModel.a69 = record.departmentId ? record.departmentId : '-';
      airModel.a70 = record.orderNum;
      airRecord.push(airModel);
      if (i == tableAirData.length - 1) {
        exportDataBit.value[0] = false;
      }
    }
    //用车
    for (let i = 0; i < tableCarData.length; i++) {
      let carModel = {
        id: 1,
        a0: '终端类型',
        a1: '预订时间',
        a2: '预订人',
        a3: '出差申请单号',
        a4: '订单号',
        a5: '员工编号',
        a6: '乘车人',
        a7: '乘车人电话',
        a8: '上车地点',
        a9: '下车地点',
        a10: '用车时间',
        a11: '车型等级',
        a12: '供应商渠道',
        a13: '出差人数',
        a14: 0,
        a15: 0,
        a16: 0,
        a17: 0,
        a18: 0,
        a19: 0,
        a20: '车辆信息',
        a21: '订单类型',
        a22: '服务商编码',
        a23: '客户名称',
        a24: '客户编号',
        a25: '收款状态',
        a26: '结算状态',
        a27: '联系人',
        a28: '联系人电话',
        a29: '成本中心',
        a30: 'OA申请单号',
        a31: '业务经理',
        a32: '服务商名称',
        a33: '服务费',
        a34: '供应商单号',
        a35: '订单来源',
        a36: '预订人部门',
        a37: '支付状态',
        a38: '支付方式',
        a39: '个人支付金额',
        a40: '个人退款金额',
        a41: 0,
        a42: '公司退款金额',
        a43: '交易流水号',
        a44: '费用承担部门',
        a45: '项目编号',
        a46: '项目名称',
        a47: '差旅事项',
        a48: '超标原因',
        a49: '超标金额',
        a50: '超标描述',
        a51: '费用类型',
        a52: '差旅授权号',
        a53: '审批状态',
        a54: '给审批人留言',
        a55: '审批组1类型',
        a56: '审批组1审批人',
        a57: '审批组2类型',
        a58: '审批组2审批人',
        a59: '审批组3类型',
        a60: '审批组3审批人',
        a61: '审批组4类型',
        a62: '审批组4审批人',
        a63: '员工部门',
        a64: '0',
        // a65: '订单号',
        // a66: '出发时间',
        a67: '抵达时间',
        a68: '乘车人卡号',
      };
      let record = tableCarData[i];
      carModel.id = i + 1;
      carModel.a0 = 'app';
      carModel.a1 = dayjs(record.createTime).format('YYYY/MM/DD HH:mm:ss');
      carModel.a2 = record.reserveName;
      carModel.a3 = record.externalApprovalNo ? record.externalApprovalNo : '-';
      carModel.a4 = record.orderNo;
      carModel.a5 = record.accountNo;
      carModel.a6 = record.orderDetailDto.passengerList[0].name;
      carModel.a7 = record.orderDetailDto.passengerList[0].phone;
      carModel.a8 = record.departCityName + '-' + record.departAddress;
      carModel.a9 = record.arriveCityName + '-' + record.arriveAddress;
      carModel.a10 = record.departureTime
        ? dayjs(record.departureTime).format('YYYY/MM/DD HH:mm:ss')
        : '-';
      // carModel.a11 = record.carCategory;
      if (record.carCategory === 'COMFORT') carModel.a11 = '舒适型';
      if (record.carCategory === 'ECONOMIC') carModel.a11 = '经济型';
      carModel.a12 = record.orderDetailDto.childChannelName
        ? record.orderDetailDto.childChannelName
        : '-';
      carModel.a13 = record.orderDetailDto.passengerList.length;
      carModel.a14 = record.realFee;
      carModel.a15 = 0;
      carModel.a16 = 0;
      carModel.a17 = record.realFee;
      carModel.a18 = record.realFee;
      carModel.a19 = record.realFee;
      carModel.a20 = record.orderDetailDto.driver ? record.orderDetailDto.driver.licensePlate : '-';
      carModel.a21 = '有审批单';
      carModel.a22 = record.orderDetailDto.proxyId;
      carModel.a23 = record.orderDetailDto.passengerList[0].name;
      carModel.a24 = record.accountNo;
      carModel.a25 = record.payStatus === 'UNPAID' ? '未支付' : '已支付';
      carModel.a26 = '-';
      carModel.a27 = record.reserveName;
      carModel.a28 = record.orderDetailDto.passengerList[0].phone;
      carModel.a29 = '-';
      carModel.a30 = record.externalApprovalNo != null ? record.externalApprovalNo : '-';
      carModel.a31 = '-';
      carModel.a32 = '-';
      carModel.a33 = '0';
      carModel.a34 = record.orderDetailDto.channelOrderNo
        ? record.orderDetailDto.channelOrderNo
        : '-';
      carModel.a35 = '-';
      carModel.a36 = record.departmentId ? record.departmentId : '-';
      carModel.a37 = '已支付';
      carModel.a38 = '月结';
      carModel.a39 = '0';
      carModel.a40 = '0';
      carModel.a41 = record.realFee;
      carModel.a42 = '0';
      carModel.a43 = '-';
      carModel.a44 = '-';
      carModel.a45 = '-';
      carModel.a46 = '-';
      carModel.a47 = '-';
      carModel.a48 = '-';
      carModel.a49 = '0';
      carModel.a50 = '-';
      carModel.a51 = '-';
      carModel.a52 = '-';
      carModel.a53 = '-';
      carModel.a54 = '-';
      carModel.a55 = '-';
      carModel.a56 = '-';
      carModel.a57 = '-';
      carModel.a58 = '-';
      carModel.a59 = '-';
      carModel.a60 = '-';
      carModel.a61 = '-';
      carModel.a62 = '-';
      carModel.a63 = record.departmentId ? record.departmentId : '-';
      carModel.a64 = 'car' + record.id;
      // carModel.a65 = record.orderNo;
      // carModel.a66 = record.departureTime
      //   ? dayjs(record.departureTime).format('YYYY/MM/DD HH:mm:ss')
      //   : '-';
      carModel.a67 = record.finishTime
        ? dayjs(record.finishTime).format('YYYY/MM/DD HH:mm:ss')
        : '-';
      carModel.a68 = record.orderDetailDto.passengerList[0].certNo
        ? record.orderDetailDto.passengerList[0].certNo
        : '-';
      carRecord.push(carModel);
      if (i == tableCarData.length - 1) {
        exportDataBit.value[1] = false;
      }
    }

    // 酒店
    for (let i = 0; i < tableHotelData.length; i++) {
      let record = tableHotelData[i];
      var hotelModel = {
        id: 1,
        1: '0',
        2: '0',
        3: '0',
        4: '0',
        5: '0',
        6: '0',
        7: '0',
        8: '0',
        9: '-',
        10: '-',
        11: '-',
        17: '-',
        18: '-',
        19: '-',
        20: '-',
        21: '-',
        22: '-',
        23: '-',
        24: '-',
        25: '-',
        26: '-',
        27: '-',
        28: '-',
        29: '-',
        30: '-',
        31: '-',
        32: '-',
        33: '-',
        34: '-',
        35: '-',
        36: '-',
        37: '-',
        CBJE: 0, // 差标金额
        40: '-',
        CCSQDH: '出差申请单号',
        DDH: '订单号',
        DDLX: '订单类型',
        DDQK: '订单情况',
        GYSDH: '供应商单号',
        RZRBM: '入住人部门',
        SBYKK: 0,
        TKJE: 0,
        YDR: '预订人',
        YDRBM: '预订人部门',
        YSZJ: 0,
        ZDLX: '终端类型',
        ZJEBHFWD: 0,
        accountNo: '预订人编号',
        amount: 0, //'个人支付金额'
        arrivalDate: '入住日期',
        busiManage: '业务经理',
        certNo: '入住人卡号',
        channelName: '渠道',
        chucairenshu: '出差人数',
        companyAmount: 0,
        costDeptName: '成本中心',
        createTime: '预订时间',
        departureDate: '离店日期',
        geoName: '城市',
        hotelName: '酒店名称',
        jianyeshu: '间夜数',
        mobile: '联系人电话',
        money: 0,
        names: '入住人',
        // orderId: '订单号',
        payType: '支付方式',
        priceAvg: '日均价',
        refundAmount: 0, //'个人退款金额',
        refundCompanyAmount: 0, // 公司退款金额
        roomCount: 0,
        roomName: '房型',
        serialNum: '交易流水号',
        status: '订单状态',
        travelType: '预订类型',
        voucherId: 'OA申请单号',
        recordId: '0',
        hotelLeave: '舒适型', // 酒店级别
      };
      let jys = getDays(tableHotelData[i].arrivalDate, tableHotelData[i].departureDate);
      // let priceAvg = tableHotelData[i].orderDetailDto.totalPay / jys;
      let priceAvg =
        tableHotelData[i].orderDetailDto.status === 'CANCEL'
          ? (tableHotelData[i].orderDetailDto.totalPay / jys).toFixed(2)
          : (tableHotelData[i].orderDetailDto.totalPay / jys).toFixed(2);

      hotelModel.id = i + 1;
      hotelModel.CCSQDH = record.voucherId;
      hotelModel.DDH = record.orderId;
      hotelModel.DDLX = '国内酒店';
      hotelModel.DDQK =
        record.status === 'WAIT_CONFIRM'
          ? '等待确认'
          : record.status === 'WAIT_PAY'
          ? '等待支付'
          : record.status === 'CONFIRM'
          ? '已确认'
          : record.status === 'NO_SHOW'
          ? '未入住'
          : record.status === 'CHECK_OUT'
          ? '已离店'
          : record.status === 'CANCEL'
          ? '已取消'
          : record.status === 'CHECK_IN'
          ? '已入住'
          : '无效';
      hotelModel.GYSDH = record.orderDetailDto.serverId;
      hotelModel.RZRBM = record.departmentId;
      hotelModel.SBYKK =
        record.status === 'CANCEL'
          ? -record.orderDetailDto.totalPay + record.amount
          : record.orderDetailDto.totalPay - record.amount;
      hotelModel.TKJE = record.status === 'CANCEL' ? record.orderDetailDto.totalPay : 0;
      hotelModel.YDR = record.orderDetailDto.names;
      hotelModel.YDRBM = record.departmentId;
      hotelModel.YSZJ =
        record.status === 'CANCEL'
          ? -record.orderDetailDto.totalPay
          : record.orderDetailDto.totalPay;
      hotelModel.ZDLX = record.orderDetailDto.createBy === 'API接口' ? 'app' : '票务';
      hotelModel.ZJEBHFWD =
        record.status === 'CANCEL'
          ? -record.orderDetailDto.totalPay
          : record.orderDetailDto.totalPay;
      hotelModel.accountNo = record.accountNo;
      hotelModel.busiManage = record.orderDetailDto.busiManage
        ? record.orderDetailDto.busiManage
        : '-';
      hotelModel.certNo = record.orderDetailDto.customers[0].certNo;
      hotelModel.channelName = record.orderDetailDto.channelName;
      hotelModel.chucairenshu = '1';
      hotelModel.costDeptName = record.orderDetailDto.customers[0].costDeptName
        ? record.orderDetailDto.customers[0].costDeptName
        : '-';
      // hotelModel.createTime = dayjs(record.orderDetailDto.createTime).format('YYYY/MM/DD HH:mm:ss');
      if (record.status === 'CANCEL') {
        hotelModel.createTime = dayjs(record.orderDetailDto.lastOptime).format(
          'YYYY/MM/DD HH:mm:ss',
        );
      } else {
        hotelModel.createTime = dayjs(record.orderDetailDto.createTime).format(
          'YYYY/MM/DD HH:mm:ss',
        );
      }

      hotelModel.arrivalDate = record.arrivalDate
        ? dayjs(record.arrivalDate).format('YYYY/MM/DD')
        : '-';
      hotelModel.departureDate = hotelModel.departureDate
        ? dayjs(record.departureDate).format('YYYY/MM/DD')
        : '-';
      hotelModel.geoName = record.orderDetailDto.geoName;
      hotelModel.hotelName = record.orderDetailDto.hotelName;
      hotelModel.jianyeshu = jys.toString();
      hotelModel.mobile = record.orderDetailDto.contact.mobile;
      hotelModel.money =
        record.status === 'CANCEL'
          ? -record.orderDetailDto.totalPay
          : record.orderDetailDto.totalPay;
      hotelModel.names = record.orderDetailDto.names;
      // hotelModel.orderId = record.orderId;
      hotelModel.payType = record.payType === 'SelfPay' ? '前台自付' : '月结';
      hotelModel.priceAvg = priceAvg.toString();

      hotelModel.roomCount = record.orderDetailDto.roomCount;
      hotelModel.roomName = record.orderDetailDto.roomName;
      hotelModel.status =
        record.status === 'WAIT_CONFIRM'
          ? '等待确认'
          : record.status === 'WAIT_PAY'
          ? '等待支付'
          : record.status === 'CONFIRM'
          ? '已确认'
          : record.status === 'NO_SHOW'
          ? '未入住'
          : record.status === 'CHECK_OUT'
          ? '已离店'
          : record.status === 'CANCEL'
          ? '已取消'
          : record.status === 'CHECK_IN'
          ? '已入住'
          : '无效';
      hotelModel.travelType = record.travelType === '0' ? '有审批单' : '无审批单';

      hotelModel.amount = record.amount;
      hotelModel.refundAmount = record.status === 'CANCEL' ? record.amount : 0;
      hotelModel.companyAmount =
        record.status === 'CANCEL' ? -record.companyAmount : record.companyAmount;
      hotelModel.refundCompanyAmount = record.status === 'CANCEL' ? record.companyAmount : 0;
      hotelModel.serialNum = record.serialNum ? record.serialNum : '-';
      hotelModel.voucherId = record.voucherId;
      hotelModel.recordId = 'hotel' + record.id;
      hotelModel.hotelLeave = record.orderDetailDto.assist.hotelCategory
        ? record.orderDetailDto.assist.hotelCategory
        : '-';
      hotelModel.CBJE = record.standardPrice;
      hotelRecord.push(hotelModel);
      if (i == tableHotelData.length - 1) {
        exportDataBit.value[2] = false;
      }
    }
    //火车
    for (let i = 0; i < tableTrainData.length; i++) {
      var trainModel = {
        id: 1,
        a0: 'app',
        a1: '预订时间',
        a2: '预订人',
        a3: '出差申请单号',
        a4: '订单号',
        a5: '12306订单号',
        a6: '员工编号',
        a7: '旅客姓名',
        a8: '联系电话',
        a9: '行程',
        a10: '出发日期',
        a11: '出发时间',
        a12: '到达日期',
        a13: '到达时间',
        a14: '车次',
        a15: '席别',
        a16: '座位号',
        a17: 0,
        a18: '改签手续费',
        a19: 0,
        a20: 0,
        a21: '线下出票服务费',
        a22: '凭证打印费',
        a23: '售票处服务费',
        a24: 0,
        a25: 0,
        a26: 0,
        a27: '订单类别',
        a28: '证件号',
        a29: '客票状态',
        a30: '结算状态',
        a31: '成本中心',
        a32: '联系人',
        a33: 'DBI信息',
        a34: 'OA申请单号',
        a35: '业务经理',
        a36: '原订单号',
        a37: '是否vip',
        a38: '提前预订天数',
        a39: '渠道服务费',
        a40: '预订人部门',
        a41: '操作员',
        a42: '支付方式',
        a43: '个人支付金额',
        a44: '个人退款金额',
        a45: 0,
        a46: 0,
        a47: '交易流水号',
        a48: '费用承担部门',
        a49: '项目编号',
        a50: '项目名称',
        a51: '差旅事项',
        a52: '超标原因',
        a53: '超标金额',
        a54: '超标描述',
        a55: '费用类型',
        a56: '差旅授权号',
        a57: '审批状态',
        a58: '给审批人留言',
        a59: '审批组1类型',
        a60: '审批组1审批人',
        a61: '审批组2类型',
        a62: '审批组2审批人',
        a63: '审批组3类型',
        a64: '审批组3审批人',
        a65: '审批组4类型',
        a66: '审批组4审批人',
        a67: '员工部门',
        a68: '原票价',
        a69: '',
        a70: '改签类型',
        a71: '退票时间',
        a72: '退票下单人',
        recordId: '消费记录id',
        // a74: '订单号',
        a75: '乘车人卡号',
        a76: '出发城市',
        a77: '到达城市',
      };
      let record = tableTrainData[i];
      trainModel.id = i + 1;
      trainModel.a0 = record.orderSource === '移动端' ? 'app' : '-';
      trainModel.a1 = dayjs(record.createTime).format('YYYY/MM/DD HH:mm:ss');
      trainModel.a2 = record.bookerName;
      trainModel.a3 = record.voucherId;
      trainModel.a4 = record.orderId;
      trainModel.a5 = record.idIn12306;
      trainModel.a6 = record.accountNo;
      trainModel.a7 = record.empName;
      trainModel.a8 = record.trainOrder.passengers[0].telephone;
      trainModel.a9 = record.fromStation + '-' + record.arriveStation;
      trainModel.a10 = dayjs(record.fromDate).format('YYYY/MM/DD');
      trainModel.a11 = record.fromTime + ':00';
      trainModel.a12 = dayjs(record.arriveDate).format('YYYY/MM/DD');
      trainModel.a13 = record.arriveTime + ':00';
      trainModel.a14 = record.trainCode;
      trainModel.a15 = record.seatTypeDes;
      trainModel.a16 = record.seatNo;
      trainModel.a17 = record.ticketMoney;
      trainModel.a18 =
        record.trainOrder.passengers[0].changeCharge === null
          ? 0
          : record.trainOrder.passengers[0].changeCharge;
      trainModel.a19 = record.refundCharge;
      trainModel.a20 = record.charge;
      trainModel.a21 = '0';
      trainModel.a22 = '0';
      trainModel.a23 = '0';
      trainModel.a24 =
        record.ticketMoney + record.charge + record.refundCharge + record.changeCharge;
      trainModel.a25 =
        record.ticketMoney + record.charge + record.refundCharge + record.changeCharge;
      trainModel.a26 =
        record.ticketMoney + record.charge + record.refundCharge + record.changeCharge;
      trainModel.a27 = record.travelType;
      trainModel.a28 = record.trainOrder.passengers[0].certNo
        ? record.trainOrder.passengers[0].certNo
        : '-';
      trainModel.a29 = record.travelType;
      trainModel.a30 = '-';
      trainModel.a31 = '-';
      trainModel.a32 = record.trainOrder.linkMans[0].linkManName
        ? record.trainOrder.linkMans[0].linkManName
        : '-';
      trainModel.a33 = '-';
      trainModel.a34 = record.voucherId ? record.voucherId : '-';
      trainModel.a35 = record.busiManage ? record.busiManage : '-';
      trainModel.a36 = '-';
      trainModel.a37 = '-';
      trainModel.a38 = '-';
      trainModel.a39 = '0';
      trainModel.a40 = record.departmentId ? record.departmentId : '-';
      trainModel.a41 = '-';
      trainModel.a42 = '月结';
      trainModel.a43 = '0';
      trainModel.a44 = record.refundAmount ? record.refundAmount : '-';
      // trainModel.a45 = record.ticketMoney ? record.ticketMoney : 0;

      trainModel.a45 =
        record.ticketMoney + record.charge + record.refundCharge + record.changeCharge;

      trainModel.a46 = record.refundMoney ? record.refundMoney : 0;
      trainModel.a47 = '-';
      trainModel.a48 = '-';
      trainModel.a49 = '-';
      trainModel.a50 = '-';
      trainModel.a51 = '-';
      trainModel.a52 = '-';
      trainModel.a53 = '-';
      trainModel.a54 = '-';
      trainModel.a55 = '-';
      trainModel.a56 = '-';
      trainModel.a57 = '-';
      trainModel.a58 = '-';
      trainModel.a59 = '-';
      trainModel.a60 = '-';
      trainModel.a61 = '-';
      trainModel.a62 = '-';
      trainModel.a63 = '-';
      trainModel.a64 = '-';
      trainModel.a65 = '-';
      trainModel.a66 = '-';
      trainModel.a67 = record.departmentId ? record.departmentId : '-';
      trainModel.a68 = '-';
      // record.travelType === '出票单' || record.travelType === '退票单'
      //   ? 0
      //   : record.ticketMoney
      //   ? record.trainOrder.passengers[0].ticketMoney
      //     ? -(
      //         record.trainOrder.passengers[0].ticketMoney +
      //         record.trainOrder.passengers[0].changeCharge +
      //         record.trainOrder.passengers[0].charge +
      //         record.trainOrder.passengers[0].refundMoney
      //       )
      //     : 0
      //   : 0;
      trainModel.a69 = record.trainOrder.passengers[0].quitStatus.toString()
        ? record.trainOrder.passengers[0].quitStatus.toString()
        : '-';
      trainModel.a70 = record.trainOrder.passengers[0].changeType
        ? record.trainOrder.passengers[0].changeType
        : '-';
      trainModel.a71 = record.refundDate ? record.refundDate : '-';
      trainModel.a72 = '-';
      trainModel.recordId = ('train' + record.id).toString();
      // trainModel.a74 = record.orderId;
      trainModel.a75 = record.trainOrder.passengers[0].certNo
        ? record.trainOrder.passengers[0].certNo
        : '-';
      trainModel.a76 = record.fromStation;
      trainModel.a77 = record.arriveStation;
      trainRecord.push(trainModel);
      if (i == tableTrainData.length - 1) {
        exportDataBit.value[3] = false;
      }
    }
    //补助
    for (let i = 0; i < tableSubsidyData.length; i++) {
      var subsidyModel = {
        id: 1,
        a0: '审批单号',
        a1: '单位编号',
        a2: '部门编号',
        a3: '职工编号',
        a4: '职工姓名',
        a5: '目的地',
        a6: '出发日期',
        a7: '返程日期',
        a8: '到期日期',
        a9: '交通工具',
        a10: 0,
        a11: 0,
        a12: 0,
        a13: 0,
        a14: 0,
      };
      let record = tableSubsidyData[i];
      subsidyModel.id = i + 1;
      subsidyModel.a0 = record.requestCode;
      subsidyModel.a1 = record.unitId;
      subsidyModel.a2 = record.departmentId;
      subsidyModel.a3 = record.employeeNo;
      subsidyModel.a4 = record.employeeName;
      subsidyModel.a5 = record.destination ? record.destination : '-';
      subsidyModel.a6 = dayjs(record.dateOfDeparture).format('YYYY-MM-DD');
      subsidyModel.a7 = dayjs(record.dateOfReturn).format('YYYY-MM-DD');
      subsidyModel.a8 = dayjs(record.dateOfReturnProlong).format('YYYY-MM-DD');
      subsidyModel.a9 = record.vehicle;
      subsidyModel.a10 = record.empExpensesDetail ? record.empExpensesDetail.countMeals : 0;
      subsidyModel.a11 = record.empExpensesDetail ? record.empExpensesDetail.moneyMeals : 0;
      subsidyModel.a12 = record.empExpensesDetail ? record.empExpensesDetail.countCar : 0;
      subsidyModel.a13 = record.empExpensesDetail ? record.empExpensesDetail.moneyCar : 0;
      subsidyModel.a14 = record.empExpensesDetail
        ? record.empExpensesDetail.moneyMeals + record.empExpensesDetail.moneyCar
        : 0;
      subsidyRecord.push(subsidyModel);
      if (i == tableSubsidyData.length - 1) {
        exportDataBit.value[4] = false;
      }
    }

    var wb = XLSX.utils.book_new();

    if (airRecord != undefined) {
      const cols = [{}];
      const AirTitle = [airHeaderDisplay, ...airRecord];
      const sheet1 = XLSX.utils.json_to_sheet(AirTitle, {
        header: reportsHeaderAir,
        skipHeader: true,
      });
      XLSX.utils.book_append_sheet(wb, sheet1, '飞机');
      Object.keys(airHeaderDisplay).forEach(() => {
        cols.push({ wch: 15 });
      });
      cols[0] = { wch: 8 };
      sheet1['!cols'] = cols;
    }

    if (trainRecord != undefined) {
      const cols = [{}];
      const TrainTitle = [trainHeaderDisplay, ...trainRecord];
      const sheet2 = XLSX.utils.json_to_sheet(TrainTitle, {
        header: reportsHeaderTrain,
        skipHeader: true,
      });
      XLSX.utils.book_append_sheet(wb, sheet2, '火车');
      cols[0] = { wch: 8 };
      Object.keys(trainHeaderDisplay).forEach(() => {
        cols.push({ wch: 15 });
      });
      sheet2['!cols'] = cols;
    }

    if (hotelRecord != undefined) {
      const cols = [{}];
      const HotelTitle = [hotelHeaderDisplay, ...hotelRecord];
      const sheet3 = XLSX.utils.json_to_sheet(HotelTitle, {
        header: reportsHeaderHotel,
        skipHeader: true,
      });
      XLSX.utils.book_append_sheet(wb, sheet3, '酒店');
      Object.keys(hotelHeaderDisplay).forEach(() => {
        cols.push({ wch: 15 });
      });
      cols[0] = { wch: 8 };
      sheet3['!cols'] = cols;
    }

    // const sheet4;
    if (carRecord != undefined) {
      const cols = [{}];
      const CarTitle = [carHeaderDisplay, ...carRecord];
      const sheet4 = XLSX.utils.json_to_sheet(CarTitle, {
        header: reportsHeaderCar,
        skipHeader: true,
      });
      XLSX.utils.book_append_sheet(wb, sheet4, '用车');
      Object.keys(carHeaderDisplay).forEach(() => {
        cols.push({ wch: 15 });
      });
      cols[0] = { wch: 8 };
      sheet4['!cols'] = cols;
    }
    if (subsidyRecord != undefined) {
      const cols = [{}];
      const SubsidyTitle = [subsidyHeaderDisplay, ...subsidyRecord];
      const sheet5 = XLSX.utils.json_to_sheet(SubsidyTitle, {
        header: reportsHeaderSubsidy,
        skipHeader: true,
      });
      Object.keys(subsidyHeaderDisplay).forEach(() => {
        cols.push({ wch: 15 });
      });
      XLSX.utils.book_append_sheet(wb, sheet5, '补助');
      cols[0] = { wch: 8 };
      sheet5['!cols'] = cols;
    }

    setExlStyle(wb['Sheets']['飞机']); // 设置列宽 字号等
    //addRangeBorder(wb['Sheets']['飞机']['!merges'], wb['Sheets']['飞机']);
    setExlStyle(wb['Sheets']['火车']); // 设置列宽 字号等
    //addRangeBorder(wb['Sheets']['火车']['!merges'], wb['Sheets']['火车']);
    setExlStyle(wb['Sheets']['酒店']); // 设置列宽 字号等
    //addRangeBorder(wb['Sheets']['酒店']['!merges'], wb['Sheets']['酒店']);
    setExlStyle(wb['Sheets']['用车']); // 设置列宽 字号等
    //addRangeBorder(wb['Sheets']['用车']['!merges'], wb['Sheets']['用车']);
    setExlStyle(wb['Sheets']['补助']); // 设置列宽 字号等
    let wbout = XLSXStyle.write(wb, { bookType: 'xlsx', bookSST: false, type: 'binary' });

    FileSaver.saveAs(
      new Blob([s2ab(wbout)], {
        type: 'application/octet-stream',
      }),
      excelname + '差旅订单统计表.xlsx',
    );
  };

  // 工具方法
  function s2ab(s) {
    var buf = new ArrayBuffer(s.length);
    var view = new Uint8Array(buf);
    for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xff;

    return buf;
  }

  const setExlStyle = (data) => {
    let borderAll = {
      //单元格外侧框线
      top: {
        style: 'thin',
      },
      bottom: {
        style: 'thin',
      },
      left: {
        style: 'thin',
      },
      right: {
        style: 'thin',
      },
    };
    // data['!cols'] = [];
    for (let key in data) {
      if (data[key] instanceof Object) {
        data[key].s = {
          border: borderAll,
          alignment: {
            horizontal: 'center', //水平居中对齐
            vertical: 'center',
          },
          font: {
            sz: 11,
          },
          bold: true,
          numFmt: 0,
        };
        // data['!cols'].push({ wpx: 115 });
      }
    }
    return data;
  };

  const searchData = async () => {
    searchBits.value[0] = true;
    searchBits.value[1] = true;
    searchBits.value[2] = true;
    searchBits.value[3] = true;
    searchBits.value[4] = true;

    setColumnsAir(comprehensiveAirColumns);
    reloadAir().then(() => {
      searchBits.value[0] = false;
      setColumnsTrain(comprehensiveTrainColumns);
      reloadTrain().then(() => {
        searchBits.value[1] = false;
        setColumnsHotel(comprehensiveHotelDataCoumns);
        reloadHotel().then(() => {
          searchBits.value[2] = false;
          setColumnsCar(comprehensiveCarColumns);
          reloadCar().then(() => {
            searchBits.value[3] = false;
            setColumnsSubsidy(comprehensiveSubsidyColumns);
            reloadSubsidy().then(() => {
              searchBits.value[4] = false;
            });
          });
        });
      });
    });
  };

  onMounted(() => {
    (excelname =
      getCurrentDataL().format('YYYY-MM-DD') + ',' + getCurrentDataR().format('YYYY-MM-DD')),
      nextTick(async () => {
        searchInfo.chooseDate = rangeChooseDate.value;
        searchBits.value[0] = true;
        searchBits.value[1] = true;
        searchBits.value[2] = true;
        searchBits.value[3] = true;
        searchBits.value[4] = true;

        setColumnsAir(comprehensiveAirColumns);
        reloadAir().then(() => {
          searchBits.value[0] = false;
          setColumnsTrain(comprehensiveTrainColumns);
          reloadTrain().then(() => {
            searchBits.value[1] = false;
            setColumnsHotel(comprehensiveHotelDataCoumns);
            reloadHotel().then(() => {
              searchBits.value[2] = false;
              setColumnsCar(comprehensiveCarColumns);
              reloadCar().then(() => {
                searchBits.value[3] = false;
                setColumnsSubsidy(comprehensiveSubsidyColumns);
                reloadSubsidy().then(() => {
                  searchBits.value[4] = false;
                });
              });
            });
          });
        });
      });
  });
</script>
